package org.csu.mypetstorebackstage.service;

import org.csu.mypetstorebackstage.domain.Manager;
import org.csu.mypetstorebackstage.persistence.ManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.PortUnreachableException;
import java.util.PrimitiveIterator;

@Service
public class ManagerService {
    @Autowired
    private ManagerMapper managerMapper;

    public Manager login(Manager manager) {
        System.out.println("in manager"+ manager.getManagerName()+" and "+manager.getPassword());
        Manager manager1 = managerMapper.getManagerByManagerNameAndPassword(manager);
        if (manager1 == null) {
            System.out.println("service null");
        }
        return managerMapper.getManagerByManagerNameAndPassword(manager);
    }

    public void addManager(String managername,String password,String email) {
        managerMapper.insertManager(new Manager(managername,password,email));
    }
    public void deleteManagerByManagerName(String managerName) {
        managerMapper.deleteManagerByManagerName(managerName);
    }

    public String getEmailByManagerId(String managerName){
        Manager manager = managerMapper.getManagerByManagerName(managerName);
        return manager.getEmail();
    }

    public Manager getManagerByManagerName(String managerName){return managerMapper.getManagerByManagerName(managerName);}
}
